<template>
	<view class="schedule-details">
		<navBar title="进度详情"  @goBack="uni.navigateBack()"></navBar>
			
		<view class="title-content" :style="{marginTop: `${topHeight}`}">
			<view class="data-info border-bottom">
				<view>管理人员</view>
				<view>{{ scheduleDetails.pmprManagePersonNamesStr || '' }}</view>
			</view>
			<view class="data-info border-bottom">
				<view>劳务人员</view>
				<view>{{ scheduleDetails.laborNum || 0 }}人</view>
			</view>
			<view class="data-info">
				<view>施工工法</view>
				<view>{{ scheduleDetails.constructionMethodStr || '' }}</view>
			</view>
		</view>	
		
		<view class="title">
			<view>工作量明细</view>
		</view>
		<view v-if="scheduleDetails.type" class="data-list">
			<!-- 钢环 -->
			<template v-if="scheduleDetails.type === 1">
				<view v-for="(item, index) in scheduleDetails.pmprWorkloads" :key="index" class="data-item">
					<view class="item-title border-bottom">施工工序{{ index + 1 }}</view>
					<view class="data-info border-bottom">
						<view>施工工序</view>
						<view>{{ item.steelRingProcedureName || '' }}</view>
					</view>
					<view class="data-info border-bottom">
						<view>环号</view>
						<view>{{ item.ringNumber || '' }}{{ item.unit || '' }}</view>
					</view>
					<view v-if="item.imageList && item.imageList.length" class="data-image">
						<view>施工图片</view>
						<view class="image-list">
							<image @click="previewImage(item.imageList, index1)" v-for="(item1, index1) in item.imageList" :key="index" :src="item1.url"></image>
						</view>
					</view>
				</view>
			</template>
			<!-- 微扰动 -->
			<template v-if="scheduleDetails.type === 2">
				<view v-for="(item, index) in scheduleDetails.pmprWorkloads" :key="index" class="data-item">
					<view class="item-title border-bottom">{{ item.steelRingProcedureName }}</view>
					<view class="data-info border-bottom">
						<view>孔号</view>
						<view>{{ item.ringNumber || '' }}孔</view>
					</view>
					<template v-if="item.steelRingProcedureName === '注浆'">
						<view class="data-info border-bottom">
							<view>水玻璃</view>
							<view>{{ item.loweGroutingAmount || 0 }}升</view>
						</view>
						<view class="data-info border-bottom">
							<view>水泥浆</view>
							<view>{{ item.sludgeGroutingAmount || 0 }}升</view>
						</view>
					</template>
					<view v-if="item.imageList && item.imageList.length" class="data-image">
						<view>施工图片</view>
						<view class="image-list">
							<image @click="previewImage(item.imageList, index1)" v-for="(item1, index1) in item.imageList" :key="index" :src="item1.url"></image>
						</view>
					</view>
				</view>
			</template>
			<!-- 其他 -->
			<template v-if="scheduleDetails.type === 3">
				<view v-for="(item, index) in scheduleDetails.pmprWorkloads" :key="index" class="data-item">
					<view class="item-title border-bottom">{{ item.steelRingProcedureName }}</view>
					<view class="data-info border-bottom">
						<view>工作量</view>
						<view>{{ item.workload || '' }}{{ item.unit }}</view>
					</view>
					<view v-if="item.imageList && item.imageList.length" class="data-image">
						<view>施工图片</view>
						<view class="image-list">
							<image @click="previewImage(item.imageList, index1)" v-for="(item1, index1) in item.imageList" :key="index" :src="item1.url"></image>
						</view>
					</view>
				</view>
			</template>
		</view>
		<view v-if="!scheduleDetails.pmprWorkloads || !scheduleDetails.pmprWorkloads.length" style="padding-bottom: 40px; min-height: 300px;">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" style="padding-bottom: 40px; min-height: 300px;"></u-empty>
		</view>
		
		<view class="title">材料消耗</view>
		<view class="data-list no-margin">
			<view v-for="(item, index) in (scheduleDetails.materialExpendList || [])" :key="index" class="data-item">
				<view class="item-title border-bottom">{{ item.parentTypeName }} - {{ item.deviceTypeName }}</view>
				<view class="data-info border-bottom">
					<view>规格型号</view>
					<view>{{ item.specificationModel }}</view>
				</view>
				<view class="data-info border-bottom">
					<view>消耗量</view>
					<view>{{ item.num }}{{ item.unit }}</view>
				</view>
			</view>
		</view>
		<view v-if="!scheduleDetails.materialExpendList || !scheduleDetails.materialExpendList.length" style="padding-bottom: 40px; min-height: 300px;">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
		</view>
	</view>
</template>

<script>
	import { pmProcessReportGetDetail } from '@/api/comprehensive/comprehensive.js'
	import { getSystemHeightInfo } from '@/utils/common.js'
	
	export default {
		data() {
			return {
				// 详情数据
				scheduleDetails: {},
				// 尺寸信息
				systemHeightInfo: {}
			}
		},
		computed: {
			// 顶部高度
			topHeight() {
				const { stateHeight, navbarHeight } = this.systemHeightInfo
				return `${(stateHeight + navbarHeight) || 0}px`
			}
		},
		onLoad(options) {
			this.systemHeightInfo = getSystemHeightInfo()
			if (uni.getStorageSync("_temp_schedule-details")) {
				this.scheduleDetails = uni.getStorageSync("_temp_schedule-details")
				uni.removeStorageSync("_temp_schedule-details")
			}
			this.id = Number(options.id)
			if (this.scheduleDetails && this.scheduleDetails.type === 2 && this.scheduleDetails.pmprWorkloads && this.scheduleDetails.pmprWorkloads.length) {
				this.getScheduleDetails()
			}
		},
		methods: {
			/** 预览图片 */
			previewImage(imageArray, index) {
				uni.previewImage({ urls: imageArray.map(item => item.url), current: index })
			},
			
			/** 获取详情数据 */
			getScheduleDetails() {
				pmProcessReportGetDetail({ id: this.id }).then(res => {
					// 对比数据
					if (res && res.result && res.result.pmprWorkloadList) {
						for (let i = 0; i < res.result.pmprWorkloadList.length; i++) {
							const item = res.result.pmprWorkloadList[i]
							for (let j = 0; j < this.scheduleDetails.pmprWorkloads.length; j++) {
								const item1 = this.scheduleDetails.pmprWorkloads[j]
								if (item1.ringNumber.indexOf(item.ringNumber) !== -1 && item.steelRingProcedureId === item1.steelRingProcedureId) {
									this.$set(this.scheduleDetails.pmprWorkloads, i, { ...item1, ringNumber: item.ringNumber, loweGroutingAmount: item.loweGroutingAmount, sludgeGroutingAmount: item.sludgeGroutingAmount })
									break
								}
							}
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.schedule-details {
		background: #fff;
		min-height: 100vh;
		font-size: 16px;
		.border-bottom {
			border-bottom: 1px solid #e8ebf1;
		}
		.title-content {
			border-top: 15px solid #f5f7fa;
			background: #fff;
			.data-info {
				padding: 0 16px;
				min-height: 50px;
				line-height: 22px;
				display: flex;
				align-items: center;
				justify-content: space-between;
				> view {
					padding: 0 11px;
					&:nth-of-type(1) {
						color: #445469;
						font-weight: bold;
						flex-shrink: 0;
					}
					&:nth-of-type(2) {
						color: #22204e;
						font-weight: 500;
						flex: 1;
						text-align: right;
					}
				}
			}
		}
		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #22204e;
			font-weight: bold;
			font-size: 18px;
			line-height: 25px;
			padding: 25px 22px 10px 15px;
			background: #f5f7fa;
		}
		.data-list {
			padding: 0 16px;
			background: #fff;
			line-height: 50px;
			&.no-margin .data-item {
				margin-top: 0 !important;
			}
			.data-item {
				&:nth-child(n + 1) {
					margin-top: 10px;
				}
				.item.title {
					color: #445469;
					font-weight: bold;
					font-size: 16px;
				}
				.data-info {
					margin: 0 18px;
					min-height: 50px;
					line-height: 22px;
					padding: 14px 0;
					font-weight: bold;
					font-size: 16px;
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					> view {
						&:nth-of-type(1) {
							color: #586981;
							flex-shrink: 0;
						}
						&:nth-of-type(2) {
							color: #445469;
							flex: 1;
							text-align: right;
						}
					}
				}
				.data-image {
					margin: 0 18px;
					> view:nth-of-type(1) {
						color: #586981;
						font-weight: bold;
						font-size: 16px;
						line-height: 50px;
					}
					.image-list {
						display: flex;
						flex-wrap: wrap;
						margin-bottom: 7px;
						image {
							margin: 4px 4px 0 0;
							border-radius: 4px;
							width: 90px;
							height: 70px;
						}
					}
				}
			}
		}
	}
</style>
